import { Component, OnInit } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Router} from '@angular/router'
@Component({
  selector: 'app-tag-new',
  templateUrl: './tag-new.component.html',
  styleUrls: ['./tag-new.component.css']
})
export class TagNewComponent implements OnInit {
public newTag={
id:4,
title:''
}
  constructor(
    private http:HttpClient,
    private router:Router
  ) { }

  ngOnInit(): void {
  }
  addTag(){

const id  = parseInt(window.localStorage.getItem("id"))
   let tags
    this.http.get("http://localhost:3000/tags").toPromise().then((data)=>{
    tags =data
    this.newTag.id =  tags[tags.length-1].id+1
    this.http.post("http://localhost:3000/tags",this.newTag).toPromise().then((data)=>{
      console.log(data)
        })
        })

  this.router.navigate(["/tag"])
  }

  
}
